package com.ruoyi.recycle.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.recycle.domain.ClientPrayerManagement;
import com.ruoyi.recycle.dto.ClientPrayerManagementQuery;
import com.ruoyi.recycle.service.ClientPrayerManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 许愿管理Controller
 *
 * @author Wubk
 * @date 2022-05-22
 */
@RestController
@RequestMapping("/prayer")
@Api(tags = "许愿管理")
public class ClientPrayerManagementController extends BaseController {

    @Resource
    private ClientPrayerManagementService clientPrayerManagementService;


    /**
     * 分页查询许愿管理列表
     */
    @PostMapping("/prayerPageQuery")
    @ApiOperation("分页查询许愿管理列表")
    public IPage<ClientPrayerManagement> financePageQuery(@RequestBody ClientPrayerManagementQuery query) throws Exception{
        return clientPrayerManagementService.financePageQuery(query);
    }


    /**
     * 导出许愿管理列表
     */
    @Log(title = "许愿管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出许愿管理列表")
    public void export(HttpServletResponse response, ClientPrayerManagementQuery query) {
        List<ClientPrayerManagement> list = clientPrayerManagementService.queryClientPrayerManagementList(query);
        ExcelUtil<ClientPrayerManagement> util = new ExcelUtil<ClientPrayerManagement>(ClientPrayerManagement.class);
        util.exportExcel(response, list, "许愿管理数据");
    }

    /**
     * 删除许愿管理
     */
    @Log(title = "许愿管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除许愿管理")
    @ApiImplicitParam(name = "ids", value = "id集合", dataType = "List")
    public AjaxResult remove(@PathVariable Long[] ids) {
        clientPrayerManagementService.removeClientPrayer(ids);
        return AjaxResult.success();
    }
}
